//stadium.js
//获取应用实例
var http = require("../../utils/http.js");
var config = require("../../utils/config.js");

const app = getApp()

Page({
      data: {
            tabList: [
                  {name: '文化类', id: 1},
                  {name: '艺术类', id: 2},
                  {name: '综合类', id: 3},
            ],
            teacher: [],

            currentIndex: 0,
            ossImageTypeList: ['?x-oss-process=image/crop,x_0,y_0,w_166,h_200,north', '?x-oss-process=image/crop,x_0,y_0,w_166,h_220,north'],
            backgroundList: [
                  ['../../images/bear/banner.png'],
                  ['https://dss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=1906469856,4113625838&fm=26&gp=0.jpg',
                        'https://dss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=3892521478,1695688217&fm=26&gp=0.jpg'],
            ],
            orderEntryList: [],
            activeIndex: 0,
            categoryList: [{
                  name: '文化类'
            }, {
                  name: '文化类'
            }, {
                  name: '文化类'
            },],
            query: {
                  requestType: 99,
                  content: ''
            },
            bannerData: {},
            animation: '',
            bgList: ['../../images/bear/left-active.png', '../../images/bear/middle-active.png', '../../images/bear/right-active.png'],
            bgList1: ['../../images/bear/left.png', '../../images/bear/middle.png', '../../images/bear/right.png']
      },
      onLoad() {

      },
      onShow() {
            this.getCateGory();
            this.getBanners();
      },
      getCateGory() {
            http.request({
                  method: 'GET',
                  url: '/category/categoryInfo',
                  data: {
                        parentId: 0
                  },
                  callBack: (res) => {


                        res.forEach((item, index) => {
                              item.img = this.data.bgList1[index]
                              item.activeImg = this.data.bgList[index]
                        })
                        console.log(res, 'res---')
                        this.setData({
                              categoryList: res

                        })
                        this.getTeacherlist();
                  }

            })
      },
      getBanners() {
            http.request({
                  method: 'GET',
                  url: '/indexImgs',
                  callBack: (res) => {


                        if (res) {
                              res.forEach(item => {
                                    item.imgUrl = app.globalData.imageHost + item.imgUrl
                              })

                        }
                        res.sort()
                        console.log(res,'res---')
                        this.setData({
                              bannerData: res
                        })
                  }

            })
      },
      onChange(e) {

            let index = e.currentTarget.dataset.index;
            console.log(index, 'e-----')
            let animation = wx.createAnimation({
                  duration: 100,
                  timingFunction: "linear",
                  delay: 0
            })
            animation.scale(.5).step();
            setTimeout(() => {
                  animation.scale(1).step();
                  this.setData({
                        animation: animation.export(),
                        activeIndex: index,
                        'query.requestType': this.data.categoryList[index].categoryId,
                  }, () => {

                        animation = null;
                        this.setData({
                              animation: null,

                        })

                        this.getTeacherlist();
                  })
            },)


      },
      getTeacherlist() {
            http.request({
                  url: '/index/indexTeacher',
                  method: 'GET',
                  data: this.data.query,
                  callBack: (res) => {

                        res.records.forEach((item) => {
                              item.orderPrice = parseFloat(item.orderPrice / 100)
                        })

                        this.setData({
                              teacher: res.records
                        })
                        console.log(this.data.teacher, 'res===')
                  }
            })
      },
      pageToActive(e){
            let item=e.currentTarget.dataset.current;
            // des: ""
            // imgId: 7
            // imgUrl: "2020/12/b638e9e5c19649baa0e33ce4c3d9518e.jpg"
            // link: null
            // pic: null
            // prodName: null
            // relation: null
            // seq: 2
            // shopId: 1
            // status: 1
            // title: null
            // type: -1
            // uploadTime: "2020-12-12 10:02:50"
            if(item.shopId){
                  wx.navigateTo({
                        url:'/pages/activity/index?id='+item.shopId
                  })
            }

      },
      onShareAppMessage() {
            return {}
      }
})